import { userSignApi, userLoginApi } from '@/api/login'
import { getCurrentInstance } from 'vue'
import { useStore } from '@/store'

interface IRulesForm {
  mobile: string
  password: string
}
export default function useFormProperties(router: any) {
  // 注册接口
  const store = useStore()
  const { proxy }: any = getCurrentInstance()
  const userSign = async (params: IRulesForm) => {
    const { success, message } = await userSignApi(params)
    if (success) {
      proxy.$message.success(message)
    } else {
      proxy.$message.error(message)
    }
  }
  // 登录
  const userLogin = async (params: IRulesForm) => {
    const {
      success,
      message,
      result: { status }
    } = await userLoginApi(params)
    if (success) {
      // localStorage.setItem('useStatus', status)
      store.commit('setUserStatus', status)
      router.push('/')

      proxy.$message.success(message)
    } else {
      proxy.$message.error(message)
    }
  }
  return {
    userSign,
    userLogin
  }
}
